package com.wofish.web.controller.member;

import com.wofish.common.annotation.Log;
import com.wofish.common.core.controller.BaseController;
import com.wofish.common.core.domain.AjaxResult;
import com.wofish.common.core.page.TableDataInfo;
import com.wofish.common.enums.BusinessType;
import com.wofish.common.utils.poi.ExcelUtil;
import com.wofish.framework.util.ShiroUtils;
import com.wofish.member.domain.MemberLv;
import com.wofish.member.domain.MemberLvVo;
import com.wofish.member.service.IMemberLvService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 会员等级 信息操作处理
 * 
 * @author wofish
 * @date 2019-04-21
 */
@Controller
@RequestMapping("/member/memberLv")
public class MemberLvController extends BaseController {
    private String prefix = "member/memberLv";
	
	@Autowired
	private IMemberLvService memberLvService;
	
	@RequiresPermissions("member:memberLv:view")
	@GetMapping()
	public String memberLv() {
	    return prefix + "/memberLv";
	}
	
	/**
	 * 查询会员等级列表
	 */
	@RequiresPermissions("member:memberLv:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(MemberLv memberLv) {
		startPage();
        List<MemberLvVo> list = memberLvService.queryMemberLvList(memberLv);
		return getDataTable(list);
	}
	

	/**
	 * 导出会员等级列表
	 */
	@RequiresPermissions("member:memberLv:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberLv memberLv) {
		List<MemberLvVo> list = memberLvService.queryMemberLvList(memberLv);
        ExcelUtil<MemberLvVo> util = new ExcelUtil<>(MemberLvVo.class);
        return util.exportExcel(list, "memberLv");
    }
	
	/**
	 * 新增会员等级
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存会员等级
	 */
	@RequiresPermissions("member:memberLv:add")
	@Log(title = "会员等级", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(MemberLv memberLv, HttpServletRequest request) {
		memberLv.setCreateBy(ShiroUtils.getLoginName());
		memberLv.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(memberLvService.insertMemberLv(memberLv));
	}

	/**
	 * 修改会员等级
	 */
	@GetMapping("/edit/{memberLvId}")
	public String edit(@PathVariable("memberLvId") Long memberLvId, ModelMap mmap) {
		MemberLv memberLv = memberLvService.selectMemberLvById(memberLvId);
		mmap.put("memberLv", memberLv);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存会员等级
	 */
	@RequiresPermissions("member:memberLv:edit")
	@Log(title = "会员等级", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(MemberLv memberLv) {
		memberLv.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(memberLvService.updateMemberLv(memberLv));
	}
	
	/**
	 * 删除会员等级
	 */
	@RequiresPermissions("member:memberLv:remove")
	@Log(title = "会员等级", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(memberLvService.deleteMemberLvByIds(ids));
	}
	
}
